<template>
    <div :id="id" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
import resize from '../../../assets/js/charts/resize'
export default {
    mixins: [resize],
    props: {
        lineOption: {},
        className: {
            type: String,
            default: 'chart'
        },
        id: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '100%'
        },
        height: {
            type: String,
            default: '100%'
        }
    },
    data() {
        return {
            chart: null,
        }
    },
    mounted() {
        this.initChart();
    },
    beforeDestroy() {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart() {
            // console.log(this.lineOption.dateArr)
            this.chart = echarts.init(document.getElementById(this.id))
            this.chart.setOption({
                backgroundColor: '#fff', //设置背景色
                tooltip: {
                    trigger: 'axis',
                    padding:[12,18],//提示框的内边距
                    axisPointer: {
                        lineStyle: {
                            color: '#979797',
                            type: "dashed"
                        }
                    },
                },
                xAxis: [{
                    type: 'category',
                    boundaryGap: false,//去掉左侧的间隙，使折线从最左侧开始画
                    data: this.lineOption.dateArr,
                    axisLine: {
                        lineStyle: {
                            color: "#E6EDF2"
                        }
                    },
                    axisLabel: {
                        margin: 10,
                        textStyle: {
                            color: "#666",
                            fontSize: 12
                        }
                    },
                    axisTick:{
                        //隐藏刻度线
                        show:false,
                    }
                }],
                yAxis: [{
                    type: 'value',
                    // splitNumber: 4,
                    splitLine: {
                        lineStyle: {
                            color: "transparent"
                        }
                    },
                    axisLine: {
                        show: false,
                        lineStyle: {
                            color: "transparent"
                        },
                    },
                    nameTextStyle: {
                        color: "#fff"
                    },

                }],
                series:this.lineOption.lineSeries
            })
        }
    }
}
</script>